package com.manpower.web;


import com.manpower.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("缓存测试Controller")
@RequestMapping("/api")
@RestController
public class ChcheTest {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 设置缓存数据
     * @return
     */
    @ApiOperation("添加缓存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key",value = "缓存key",required = true,dataType = "string"),
            @ApiImplicitParam(name = "value",value = "缓存key对应值",required = true,dataType = "string")
    })
    @PostMapping("/setCache")
    public String setCache(String key,String value){
        redisUtil.put(key,value,-1);

        /*UserDto user = new UserDto();
        user.setId(99);
        user.setUserName("WWY");

        redisUtil.put(key,user,0);*/
        return "success";
    }

    /**
     * 获取缓存数据
     * @param key
     * @return
     */
    @ApiOperation("获取缓存数据")
    @ApiImplicitParam(name = "key",value = "缓存key",required = true,dataType = "string")
    @PostMapping("/getCache")
    public String getCache(String key){
        String key1 = "";
        key1 = redisUtil.get(key, String.class);

        //UserDto user = redisUtil.get(key, UserDto.class);

        return "key1>>>>" + key1;
    }
}
